import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    role: 0,//标识用户身份
    userinfo: {}//用户信息
  },
  getters: {
    roleName(state) {
      return state.role === 1 ? '超管' : state.role === 2 ? '宿管' : '学生'
    }
  },
  mutations: {
    //设置用户信息
    setUser(state, res) {
      // state.userinfo 
      state.userinfo = res.user
      state.role = res.role
      console.log(state.userinfo);
      console.log(state.role);
    },
    //清空
    clearUser(state) {
      state.role = 0
      state.userinfo = {}
    }
  },
  actions: {
  },
  modules: {
  }
})
